package org.dromara.system.service.impl;

import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.utils.BeanCopyUtils;
import org.dromara.system.mapper.SysDictTypeMapper;
import org.dromara.system.pojo.bo.SysDictTypeBO;
import org.dromara.system.pojo.entity.SysDictTypeDO;
import org.dromara.system.pojo.qo.SysDictTypeQO;
import org.dromara.system.pojo.vo.SysDictTypeVO;
import org.dromara.system.service.SysDictTypeService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 字典类型表 服务层实现。
 *
 * @author mkj
 * @since 2024-07-21
 */
@RequiredArgsConstructor
@Service
public class SysDictTypeServiceImpl implements SysDictTypeService {

    private final SysDictTypeMapper sysDictTypeMapper;

    @Override
    public boolean add(SysDictTypeBO sysDictTypeBO) {
        SysDictTypeDO sysDictTypeDO = BeanCopyUtils.copy(sysDictTypeBO, SysDictTypeDO.class);
        return sysDictTypeMapper.insert(sysDictTypeDO) > 0;
    }

    @Override
    public boolean remove(Long id) {
        return sysDictTypeMapper.deleteById(id) > 0;
    }

    @Override
    public boolean update(SysDictTypeBO sysDictTypeBO) {
        SysDictTypeDO sysDictTypeDO = BeanCopyUtils.copy(sysDictTypeBO, SysDictTypeDO.class);
        return sysDictTypeMapper.update(sysDictTypeDO) > 0;
    }

    @Override
    public List<SysDictTypeVO> list(SysDictTypeQO sysDictTypeQO) {
        SysDictTypeDO sysDictTypeDO = BeanCopyUtils.copy(sysDictTypeQO, SysDictTypeDO.class);
        QueryWrapper queryWrapper = QueryWrapper.create(sysDictTypeDO);
        return sysDictTypeMapper.selectListByQueryAs(queryWrapper, SysDictTypeVO.class);
    }

    @Override
    public SysDictTypeVO getInfo(Long id) {
        SysDictTypeDO sysDictTypeDO = sysDictTypeMapper.selectOneById(id);
        if (sysDictTypeDO == null) {
            return null;
        }
        return BeanCopyUtils.copy(sysDictTypeDO, SysDictTypeVO.class);
    }

    @Override
    public Page<SysDictTypeVO> page(SysDictTypeQO page) {
        return sysDictTypeMapper.paginateAs(page.getPageNumber(), page.getPageSize(), QueryWrapper.create(page), SysDictTypeVO.class);
    }

}

